const mysql = require("mysql");
exports.bass = (sql,data,callback) =>{
    //第2步：创建mysql数据库连接
    let conn = mysql.createConnection({
        host: "dcsgo.top",
        port: 3306,
        user: "dcs",
        password: "12071207@dcsLB",
        database: "project02db"
    });

    //第3步：连接数据库
    conn.connect();

    // //第4步：准备SQL语句
    // let sql = "select * from ProductDetails";

    // //第5步：执行上面的sql
    // conn.query(sql, (error, result,fields) => {
    //     if (error) throw error;{
    //         console.log("数据库语句执行失败");
    //         console.log(error);
    //     }
    //     console.log("数据库执行成功");
    //     console.log(result); 
    // });

    conn.query(sql,data,(error,results,fields) =>{
        if(error) throw error;{
            console.log("数据库语句执行失败");
            console.log(error);
        }
        console.log("数据库执行成功");
        console.log(results);
        callback && callback(results,error)
    })

    //第6步：SQL语句执行完成以后，数据库的连接要关闭
    conn.end();
}